package com.bruce.springcloud.provider.payment.controller;

import com.bruce.springcloud.common.CommonResult;
import com.bruce.springcloud.common.Payment;
import com.bruce.springcloud.provider.payment.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.Resource;

@RestController
@RequestMapping("/payment")
@Slf4j
public class OrderPaymentController {

    @Value("${server.port}")
    private String serverPort;
    @Resource
    private PaymentService paymentService  ;

    @GetMapping("/showServerPort")
    public CommonResult<String> showServerPort(){
        CommonResult<String> result = new CommonResult<>() ;
        result.setData("server port :" + serverPort);
        result.setMessage("success....");
        result.setCode(200);
        return result ;
    }


    /**
     * 根据Id 获取付款流水号
     * @return
     */
    @GetMapping("/findById/{id}")
    public CommonResult<Payment> findById(@PathVariable("id") Long id){
        log.info("........findById....id = {}" ,id);
        CommonResult<Payment> result = new CommonResult<>() ;
        Payment payment = paymentService.findById(id) ;
        if(payment == null){
            result.setCode(300);
            result.setMessage("找不到对应的记录!");
            return result ;
        }
        result.setCode(400);
        result.setMessage("success server port:" + serverPort);
        result.setData(payment);
        return result ;
    }


}
